package cn.org.timespace.easyframe.util.sms.telecom;

import java.io.IOException;
import java.util.Date;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import cn.org.timespace.easyframe.util.sms.telecom.smsUtil.SMGPPropertie;

import com.huawei.insa2.comm.smgp.message.SMGPMessage;
import com.huawei.insa2.comm.smgp.message.SMGPSubmitRespMessage;

public class SendMsg {

	private final static Log log = LogFactory.getLog(MySMGPSMProxy.class);

	private static final int msgType = Integer.parseInt(SMGPPropertie
			.getProperty("smgp.msgType").trim());// ����Ϣ����
	private static final int needReport = Integer.parseInt(SMGPPropertie
			.getProperty("smgp.needReport").trim());// �Ƿ�Ҫ�󷵻�״̬����
	private static final int priority = Integer.parseInt(SMGPPropertie
			.getProperty("smgp.priority").trim());// ���͵����ȼ�
	private static final String serviceId = SMGPPropertie.getProperty(
			"smgp.serviceId").trim();// ҵ������
	private static final String feeType = SMGPPropertie.getProperty(
			"smgp.feeType").trim();// �ʷ�����
	private static final String feeCode = SMGPPropertie.getProperty(
			"smgp.feeCode").trim();// �ʷѴ���
	private static final String fixedFee = SMGPPropertie.getProperty(
			"smgp.fixedFee").trim();// ���·�/�ⶥ�� ����λ���֣�
	private static final int msgFormat = Integer.parseInt(SMGPPropertie
			.getProperty("smgp.msgFormat").trim());// ����Ϣ��ʽ
	private static final Date validTime = null;// ��Чʱ�� smgp.validTime
	private static final Date atTime = null;// ����ʱ�� smgp.atTime
	private static final String srcTermId = SMGPPropertie.getProperty(
			"smgp.srcTermId").trim();// ����Ϣ�����û�����
	private static final String chargeTermId = SMGPPropertie.getProperty(
			"smgp.chargeTermId").trim();// �Ʒ��û�����

	/**
	 * @param MySMGPSMProxy
	 *            proxy notNull
	 * @param String
	 *            [] destTermId notNull ���Ž��պ���
	 * @param String
	 *            content Null ��������
	 * */
	public synchronized static boolean send(MySMGPSMProxy proxy,
			String[] destTermId, String content) {
		boolean bool = false;
		try {
			/**
			 * ����һ���Ͷ�����Ϣ,������Ϣ�ĸ��ֶε�ֵ�����Ը����ֵ�����жϣ������Ҫ�����׳��쳣
			 * ��Ҫ�������Ĳ���ת��Ϊһ��byte���͵�����
			 * 
			 * @param int msgType ����Ϣ����
			 * @param int needReport �Ƿ�Ҫ�󷵻�״̬����
			 * @param int priority ���͵����ȼ�
			 * @param String
			 *            serviceId ҵ������
			 * @param String
			 *            feeType �ʷ�����
			 * @param String
			 *            feeCode �ʷѴ���
			 * @param String
			 *            fixedFee ���·�/�ⶥ�� ����λ���֣�
			 * @param int msgFormat ����Ϣ��ʽ
			 * @param Date
			 *            validTime ��Чʱ��
			 * @param Date
			 *            atTime ����ʱ��
			 * @param String
			 *            srcTermId ����Ϣ�����û�����
			 * @param String
			 *            chargeTermId �Ʒ��û�����
			 * @param String
			 *            [] destTermId ����Ϣ���պ���
			 * @param String
			 *            msgCount ����Ϣ����
			 * @param String
			 *            reserve �����ֶ�
			 */
			int destLen = destTermId.length;
			for (int i = 0; i < destLen; i++) {
				String[] dest = { destTermId[i] };
				SMGPMessage submitMsg = new SMGPSubmit30Message(msgType,
						needReport, priority, serviceId, feeType,// �ʷ�����
						"", // �ʷѴ���
						"", // ���·�/�ⶥ�� ����λ���֣�
						msgFormat, null, null, srcTermId, destTermId[0], // �ƷѺ���
																			// chargeTermId
						dest, content, "0");
				SMGPSubmitRespMessage repMsg = (SMGPSubmitRespMessage) proxy
				.send(submitMsg);
				if (0 == repMsg.getStatus()) {
					bool = true;
				}
				log.info("�����ύ״̬��"+repMsg.getStatus());
			}
			
			// �˳�
			// proxy.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return bool;
	}
}
